const app = getApp();
Component({
  /**
   * 组件的一些选项
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的对外属性
   */
  properties: {
    bgColor: {
      type: String,
      default: ''
    },
    isCustom: {
      type: [Boolean, String],
      default: false
    },
    isBack: {
      type: [Boolean, String],
      default: false
    },
    bgImage: {
      type: String,
      default: ''
    },
    backUrl: {
      type: String,
      default: '',
      observer: function (newVal) {
        console.log(newVal)
        this.setData({
          backUrl: newVal
        })
      }
    },
    backType: {
      type: String,
      default: '',
      observer: function (newVal) {
        console.log(newVal)
        this.setData({
          backType: newVal
        })
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    backUrl: '',
    backType: ''
  },
  /**
   * 组件的方法列表
   */
  methods: {
    BackPage() {
      let backUrl = this.data.backUrl
      console.log(backUrl)
      if (backUrl && backUrl != '') {
        let backType = this.data.backType
        switch(backType){
          case 'tab':
            wx.switchTab({
              url: backUrl,
            })
            break;
          default:
            wx.redirectTo({
              url: backUrl,
            })
        }
      } else {
        wx.navigateBack({
          delta: 1
        });
      }
    },
    toHome() {
      wx.reLaunch({
        url: '/pages/index/index',
      })
    }
  }
})